package com.fh.modules.pms.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fh.common.api.vo.Result;
import com.fh.common.aspect.annotation.AutoLog;
import com.fh.common.constant.CommonConstant;
import com.fh.common.query.QueryWrapperUtil;
import com.fh.common.util.ConvertUtils;
import com.fh.modules.pms.entity.PmsProductProperty;
import com.fh.modules.pms.service.IPmsProductPropertyService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;

import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

 /**
 * @Title: Controller
 * @Description: 商品规格表
 * @author： code generator
 * @date：   2019-09-26
 * @version： V1.0
 */
@RestController
@Slf4j
@Api("商品规格表")
public class PmsProductPropertyController {
	@Autowired
	private IPmsProductPropertyService pmsProductPropertyService;
	
	/**
	  * 分页列表查询
	 * @param pmsProductProperty
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@GetMapping(value = "/pms/pmsProductProperty/list")
	@ApiOperation("分页列表查询")
	@AutoLog(value="商品规格表分页查询",logType=CommonConstant.LOG_TYPE_QUERY)
	public Result queryPageList(PmsProductProperty pmsProductProperty,
									  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
									  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
									  HttpServletRequest req) {
		QueryWrapper<PmsProductProperty> queryWrapper = new QueryWrapper<PmsProductProperty>();
		QueryWrapperUtil.initQueryWrapper(queryWrapper, pmsProductProperty);
		Page<PmsProductProperty> page = new Page<PmsProductProperty>(pageNo, pageSize);
		IPage<PmsProductProperty> pageList = pmsProductPropertyService.page(page, queryWrapper);
		return Result.ok(pmsProductPropertyService.queryProperty(1));
	}
	
	/**
	  *   添加
	 * @param pmsProductProperty
	 * @return
	 */
	@PostMapping(value = "/pms/pmsProductProperty/add")
	@ApiOperation("添加")
	@AutoLog("添加商品规格表")
	public Result add(@RequestBody PmsProductProperty pmsProductProperty) {
		pmsProductPropertyService.save(pmsProductProperty);
		return Result.ok("添加成功");
	}
	
	/**
	  *  编辑
	 * @param pmsProductProperty
	 * @return
	 */
	@PutMapping(value = "/pms/pmsProductProperty/edit")
	@ApiOperation("修改")
	@AutoLog("修改商品规格表")
	public Result edit(@RequestBody PmsProductProperty pmsProductProperty) {
		boolean ok = pmsProductPropertyService.updateById(pmsProductProperty);
		return ok?Result.ok("修改成功"):Result.error("修改失败");
	}
	
	/**
	  *   通过id删除
	 * @param id
	 * @return
	 */
	@DeleteMapping(value = "/pms/pmsProductProperty/delete")
	@ApiOperation("通过id删除")
	@AutoLog("删除商品规格表")
	public Result delete(@RequestParam(name="id",required=true) String id) {
		pmsProductPropertyService.deleteEntityByDelFlag(id);
		return Result.ok("删除成功");
	}
	
	/**
	  *  批量删除
	 * @param ids
	 * @return
	 */
	@DeleteMapping(value = "/pms/pmsProductProperty/deleteBatch")
	@ApiOperation("批量删除")
	@AutoLog("批量删除商品规格表")
	public Result deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		pmsProductPropertyService.deleteBatchEntityByDelFlag(ids);
		return Result.ok("批量删除成功");
	}
	
	/**
	  * 通过id查询
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/pms/pmsProductProperty/queryById")
	@ApiOperation("通过id查询")
	@AutoLog(value="商品规格表通过id查询",logType=CommonConstant.LOG_TYPE_QUERY)
	public Result queryById(@RequestParam(name="id",required=true) String id) {
		PmsProductProperty pmsProductProperty = pmsProductPropertyService.getById(id);
		return Result.ok(pmsProductProperty);
	}

}
